home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4075 < prev    next >
Encoding:
Text File  |  1996-08-06  |  849 b   |  31 lines

  1. Path: galaxy.ucr.edu!not-for-mail
  2. From: thp@cs.ucr.edu (Tom Payne)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: popen() equivalent in c++
  5. Date: 27 Jan 1996 19:39:44 GMT
  6. Organization: University of California, Riverside Department of Computer Science
  7. Message-ID: <4edv20$si6@galaxy.ucr.edu>
  8. References: <Pine.SUN.3.91.960123133630.6989A-100000@lab-208-10>
  9. NNTP-Posting-Host: corvette.ucr.edu
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Jason Hess (hess@mendoza.mathcs.unbc.edu) wrote:
  13. : There must be a popen() equivalent in c++ but I can't seem to find it.  
  14. : I'm using g++2.7.0.  Help me.
  15. : Jason Hess.
  16.  
  17.  
  18. The following works under g++ 2.6.3 under Linux:
  19.  
  20. int main() {
  21.     ifstream inpipe( fileno( popen("ls", "r") ) );
  22.     if ( ! inpipe ) perror("failed");
  23.     char c;
  24.     while ( inpipe.get(c) ) cout << c;
  25.     return 0;
  26. }
  27.  
  28.  
  29. Tom Payne (cs.ucr.edu)
  30.